package TCP;

import java.io.*;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) throws IOException {
        //创建socket和服务器连接
        Socket socket = new Socket("127.0.0.1", 8888);

        //获得输入输出流
        InputStream in = socket.getInputStream();
        OutputStream out = socket.getOutputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        PrintWriter writer = new PrintWriter(out);

        //发送数据
        writer.println("hello");
        writer.flush();

        //接收
        String s = reader.readLine();
        System.out.println(s);

        //释放资源
        socket.close();
    }
}
